package com.esp.app.air;

import android.content.Context;
import android.content.Intent;
import android.provider.Settings;
import android.util.Log;

public class AirplanModel {
	
	private static final String TAG = AirplanModel.class.getName();

	public static Boolean getAirModeState(final Context context) 
	{
		int state = Settings.System.getInt(context.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, 0);
		Log.v(TAG,"getAirModeState :|=> " +  state);
		Boolean AirplanState = null;
		switch (state) {
        case 1:
        	//airplaneMode is enabled.
            AirplanState = true;
            break;
        case 0:
        	//airplaneMode is disable.
            AirplanState = false;
            break;
        default:
            break;
        }
		Log.v(TAG,"getAirModeState :|=> " +  AirplanState);
		return AirplanState;
	}

	public static void setAirModeState(final Context context) 
	{
		boolean isEnabled = Settings.System.getInt(
				context.getContentResolver(), Settings.System.AIRPLANE_MODE_ON,
				0) != 0;

		// toggle airplane mode
		Settings.System.putInt(context.getContentResolver(),
				Settings.System.AIRPLANE_MODE_ON, isEnabled ? 0 : 1);
		
		Log.v(TAG,"setAirModeState :|=> " +  isEnabled);
		
		
		// Post an intent to reload
		Intent changeMode = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
		changeMode.putExtra("state", !isEnabled);
		context.sendBroadcast(changeMode);
		context.sendBroadcast(changeMode);
	}
	

}
